home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-28 | 4.6 KB | 222 lines | [TEXT/CWIE] |
- /*
- * TransSkel++ CWindow subclass demonstration: CZoomWindow
- *
- * This module is based entirely on Paul Dubois' ZoomRect module of 20 Dec 93:
- *
- * "This module handles a window in which successive randomly generated
- * rectangles are smoothly interpolated into one another. The display
- * is white on black, which results in some interesting problems (see
- * DrawGrowBox, for instance). The display adjusts itself to the size
- * of the window, so that the zoom series always lie entirely within
- * the window. Clicking the mouse in the window pauses the display until
- * the button is released."
- *
- * The CZoomWindow class is a subclass of the CMultiSkelWindow class,
- * which in turn is a kind of CWindow.
- *
- * Modified by: fadushin 1/2/96
- * Uses: TransSkel++ 3.00
- */
-
- #include "TransSkel++.h"
- #include "CZoomWindow.h"
- #include "MultiSkel++.h"
-
-
- #define zoomSteps 15 /* # rects in interpolative series */
-
- /*
- * The ZoomSize of the window is the portRect - the right side scroll bars
- */
- void
- CZoomWindow::SetZoomSize (void)
- {
- Rect r;
-
- r = wind->portRect;
- r.right -= 15; /* don't use right edge */
- sizeX = r.right;
- sizeY = r.bottom;
- }
-
-
- /*
- * return integer between zero and max (inclusive). assumes max is
- * non-negative.
- */
-
- short
- CZoomWindow::Rand(short max)
- {
- short t;
-
- t = Random ();
- if (t < 0) t = -t;
- return (t % (max + 1));
- }
-
-
- /*
- * Interpolate one rectangle smoothly into another. Erase the previous
- * series as the new one is drawn.
- */
-
- void
- CZoomWindow::ZoomRect (Rect *r1, Rect *r2)
- {
- short r1left, r1top;
- short l, t;
- short j;
- short hDiff, vDiff, widDiff, htDiff;
- short r, b;
- short rWid, rHt;
-
- //PenPat(gray);
- r1left = r1->left;
- r1top = r1->top;
- hDiff = r2->left - r1left; /* positive if moving to right */
- vDiff = r2->top - r1top; /* positive if moving down */
- rWid = r1->right - r1left;
- rHt = r1->bottom - r1top;
- widDiff = (r2->right - r2->left) - rWid;
- htDiff = (r2->bottom - r2->top) - rHt;
- /*
- * order of evaluation is important in the rect coordinate calculations.
- * since all arithmetic is integer, you can't save time by calculating
- * j/zoomSteps and using that - it'll usually be zero.
- */
- for (j = 1; j <= zoomSteps; j++)
- {
- FrameRect (&zRect[j-1]); /* erase a rectangle */
- l = r1left + (hDiff * j) / zoomSteps;
- t = r1top + (vDiff * j) / zoomSteps;
- r = l + rWid + (widDiff * j) / zoomSteps;
- b = t + rHt + (htDiff * j) / zoomSteps;
- SetRect (&zRect[j-1], l, t, r, b);
- FrameRect (&zRect[j-1]);
- }
- }
-
-
- /*
- * Draw the grow box in white on black. I used to do this by drawing the box and
- * inverting it, but that doesn't work under System 7 which uses color tinges.
- * Now I just draw the squares directly. Ugh.
- */
-
- void
- CZoomWindow::DrawGrowBox(void)
- {
- Rect r;
- r = wind->portRect;
- r.left = r.right - 15;
- r.top = r.bottom - 15;
- ++r.right;
- ++r.bottom;
- EraseRect (&r);
- FrameRect (&r);
- if (((WindowPeek) wind)->hilited)
- {
- r.right -= 6;
- r.bottom -= 6;
- OffsetRect (&r, 4, 4);
- FrameRect (&r);
- r.right -= 3;
- r.bottom -= 3;
- OffsetRect (&r, -1, -1);
- EraseRect (&r);
- FrameRect (&r);
- }
- }
-
-
- void
- CZoomWindow::doClose(void)
- {
- HideWindow(wind);
- }
-
-
-
- /*
- * just pause zoom display while mouse down
- */
- void
- CZoomWindow::doMouseClick(Point pt, long t, short mods)
- {
- while (StillDown ()) { /* wait until mouse button released */ }
- }
-
-
- void
- CZoomWindow::doUpdate (Boolean resized)
- {
- short i;
-
- EraseRect (&wind->portRect);
- DrawGrowBox();
- SetWindClip ();
- for (i = 0; i < zoomSteps; ++i)
- FrameRect (&zRect[i]);
- ResetWindClip ();
- if (resized)
- SetZoomSize (); /* adjust to new window size */
- }
-
-
- void
- CZoomWindow::doActivate (Boolean active)
- {
-
- DrawGrowBox ();
- if (active)
- DisableItem (gApp->editMenu.GetMenuHandle(), 0);
- else
- EnableItem (gApp->editMenu.GetMenuHandle(), 0);
- DrawMenuBar ();
- }
-
-
-
-
- void
- CZoomWindow::doIdle (void)
- {
- short i;
- Point pt1, pt2;
- Rect dstRect;
-
- SetPt (&pt1, Rand (sizeX), Rand (sizeY)); /* generate new rect */
- SetPt (&pt2, Rand (sizeX), Rand (sizeY)); /* and zoom to it */
- Pt2Rect (pt1, pt2, &dstRect);
- SetWindClip (); /* don't draw in right edge */
- ZoomRect (&zSrcRect, &dstRect);
- ResetWindClip ();
- zSrcRect = dstRect;
- }
-
-
-
- CZoomWindow::CZoomWindow(short resID)
- :CMultiSkelWindow(resID, STORE_IN_HEAP, BRING_TO_FRONT, false)
- {
- short i;
-
-
- SetZoomSize ();
- BackPat ((ConstPatternParam) &qd.black);
- if (SkelQuery(skelQHasColorQD)){
- RGBColor c;
-
- c.red = 0xFFFF; // blood red
- c.green = 0x0000;
- c.blue = 0x0000;
-
- RGBForeColor(&c);
- }
- PenMode (patXor);
- SetRect (&zSrcRect, 0, 0, 0, 0);
- for (i = 0; i < zoomSteps; ++i) /* initialize rect array */
- zRect[i] = zSrcRect;
- }
-